package com.example.android.apis;

import android.app.Activity;
import android.content.Context;
import android.location.GpsStatus;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class Main extends Activity {
    /** Called when the activity is first created. */
    
    LocationManager lm;
    LocationListener locationListener;
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); 
      
        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationListener = new locListener();
        
      
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER	, 0, 0, locationListener);
        
        /*
        TextView tv = new TextView(this);
        tv.setText("Application started");
        
       setContentView(tv);*/
    }

    private class locListener implements LocationListener{
    	
    	TextView tv1 = new TextView(getBaseContext());
    	
    	
		public void onLocationChanged(Location location) {
			if (location != null)
			{
				
				//setContentView(output);
				
				tv1.append("Location changed: Lat: " + location.getLatitude() +
						"Long: " + location.getLongitude());
				setContentView(tv1);
				
				/*
				Toast.makeText(getBaseContext(),
						"Location changed: Lat: " + location.getLatitude() +
						"Long: " + location.getLongitude(),
						Toast.LENGTH_SHORT).show();*/
				
			}
			
		}

		public void onProviderDisabled(String provider) {

			
			
		}

		public void onProviderEnabled(String provider) {

		}

		public void onStatusChanged(String provider, int status, Bundle extras) {

		}
    	
    	
    } 
}